" vim-coc
set hidden
set updatetime=100
set shortmess+=c
set signcolumn=yes

inoremap <silent><expr> <TAB>
          \ coc#pum#visible() ? coc#pum#next(1) :
          \ CheckBackspace() ? "\<Tab>" :
          \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! CheckBackspace() abort
      let col = col('.') - 1
      return !col || getline('.')[col - 1]  =~# '\s'
endfunction

inoremap <silent><expr> <c-o> coc#refresh()

if exists('*complete_info')
  inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
else
  inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endif

let g:coc_global_extensions = [
                              \ 'coc-pairs',
                              \ 'coc-git',
                              \ 'coc-snippets',
                              \ 'coc-actions',
                              \ 'coc-json',
                              \ 'coc-vimlsp',
                              \ 'coc-tsserver',
                              \ 'coc-html',
                              \ 'coc-css',
                              \ 'coc-eslint',
                              \ 'coc-highlight',
                              \ 'coc-sh',
                              \ 'coc-tsserver',
                              \ 'coc-wxml',
                              \ 'coc-pyright',
                              \ 'coc-vetur',
                              \]

" 报错跳转
nmap <silent> g[ <Plug>(coc-diagnostic-prev)
nmap <silent> g] <Plug>(coc-diagnostic-next)

" 定义跳转
nmap <silent> gd <Plug>(coc-definition)
" 查找引用
nmap <silent> gr <Plug>(coc-references)

" 重命n
nmap <leader>rn <Plug>(coc-rename)

" 格式化当前文件
command! -nargs=0 Format :call CocAction('format')
